import Mockjs from 'mockjs'
import arr from './zhuce'
import { setToken } from '../utils/cookieUtils'
Mockjs.mock(/\/login/, 'post', loginFn)

function loginFn(data) {

    let obj = JSON.parse(data.body)
    let token = ''
    arr.map(item => {
        if (item.password == obj.pass && item.user == obj.text) {
            item.token = item.user + '------token----'
            token = item.token
            console.log(token);
            setToken('token', (token || 'xiaoming------token----'))
        }
    })

    if (token) {
        return {
            code: 200,
            res: '登录成功'

        }
    } else {
        return {
            code: 201,
            res: '登录失败'
        }

    }


}